// 判断是否登录 没有就拦截 返回登录页面
window.$check.checkLogin();

// 引入当前的css
require("../css/sports.less")


document.ready(function () {
    // 引入动态tab栏
    window.$check.tabs(1);

    // 用户id
    let userId = JSON.parse(localStorage.getItem("user")).userId;
    const BASE_URL = 'http://139.9.177.51:8099' // 接口请求的 URL
    const news = document.querySelector(".news");
    window.$http.get("/sports/courseList?id=" + userId, function (res) {
        console.log(res);
        const latest = res.data.find(item => item.latest === 1);
        // console.log(latest);
        news.innerHTML = `
        <a href = "./sports-data.html?id=${latest.courseId}">
            <div class = "img-box" style = "background-image:url(${BASE_URL + latest.imgurl})" ></div>
            <div class = "intro">
                <p>${latest.name}</p>
                <span>${latest.desc}</span>
            </div>
        </a>
        `
        const classArr = res.data.filter(item => item.latest !== 1);
        const course = document.querySelector(".course");
        let str = '';
        classArr.forEach(function (v) {
            str += `
            <a href = "./sports-data.html?id=${v.courseId}">
            <li style = "background-image:url(${BASE_URL + v.imgurl})">
                 <p>${v.name}</p>
                 <span>${v.desc}</span>
            </li>
            </a>
            `
        })
        course.innerHTML = str
    })
})
